// 缓存需要刷新页面的路由地址
const routers = ref<string[]>([]);

// 设置需要缓存的页面路由, 刷新后需要从数组删除
export function setRefreshRouters(urls: string[]) {
  routers.value = Array.from(new Set([...unref(routers), ...urls]));
  console.log(routers, '待刷新页面');
};

// 判断当前路由是否存在于需刷新路由数组内,包含则重新调用onLoad的方法
export function refreshOnLoad(service: Function) {
  const url = uni.$u.page();
  if (url && routers.value.includes(url)) {
    routers.value = routers.value.filter(item => item !== url); // 去除已刷新地址
    const pages = uni.$u.pages();
    const { options } = pages[pages.length - 1].$page;
    service(options);
  }
};